
const goods = [2,100,2,3,3,90,3,2,80,2];

function check(goods){
    if( goods.length < 3 ) {
        return Math.min(...goods);
    } 

    if( goods.length === 3 ) {
        let sum1 = goods[0] + goods[1] ; 
        let sum2 = goods[0] + goods[2] ; 
        return Math.min( sum1 , goods[1] , sum2 );
    }

    let start = goods[0]<goods[1] ? 0 : 1 ;
    let sum = goods[ start ] ;
    for( let i = start ; i < goods.length ; i+=2 ){
        let next = goods[ i + 1 ];
        let nextNext = goods[ i + 2 ] ;
        let min = Math.min( next ,  nextNext ? nextNext : Infinity );
        console.log( `${sum} + ${min}` );
        sum += min ;
    }
    return sum ;
}

console.log( check( goods ) );